//
//  LHAreaViewController.m
//  Knight_Tour
//
//  Created by Bruce_Lin on 15/5/19.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHAreaViewController.h"
#import "LHAreaModel.h"
#import "LHAreaView.h"
#import "LHNetworkHandle.h"
#import "MyNavgationView.h"
#import "LHDetailViewController.h"

@interface LHAreaViewController ()<jumpTodetailDelegate>
@property (nonatomic ,retain)LHAreaView *areaView;
@property (nonatomic ,retain)NSMutableArray *areaArr;
@property (nonatomic ,retain)MyNavgationView *areaNavi;
@end

@implementation LHAreaViewController

- (void)dealloc
{
    [_areaView release];
    [_areaArr release];
    [_areaNavi release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.areaArr = [NSMutableArray array];
    [self creatNavi];
    [self gateData];
}

- (void)creatNavi
{
    self.areaNavi = [[MyNavgationView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    _areaNavi.leftTarget = self;
    _areaNavi.leftAction = @selector(backToCityPage);
    [_areaNavi creatLeftButtonWithImage:@"btn_nav_back"];
    [_areaNavi creatTitle:self.areaTitleName];
    [self.view addSubview:_areaNavi];
    [_areaNavi release];
}

- (void)creatAreaView
{
    self.areaView = [[LHAreaView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64)];
    self.areaView.delegate = self;
    self.areaView.AreaModelArr = self.areaArr;
    [self.view addSubview:_areaView];
    [_areaView release];
}

- (void)gateData
{
    NSString *url = [NSString stringWithFormat:@"http://119.57.103.173:8080/tsp/sightWSAction!findAllSightByID.do?id=%@",self.myAreaID];
    [LHNetworkHandle getDataWithURL:url completion:^(id result) {
        
        for (NSDictionary *tempdic in [result objectForKey:@"sights"]) {
            
            LHAreaModel *area = [[LHAreaModel alloc]initWithDic:tempdic];

            [self.areaArr addObject:area];
            [area release];
        }
        [self creatAreaView];
    }];
}

- (void)backToCityPage
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)jumpToDetailsWithIndexPath:(NSIndexPath *)indexPath
{
    LHDetailViewController *vc = [[LHDetailViewController alloc] init];
    vc.myDetailID = [self.areaArr[indexPath.item]AreaID];
    vc.detailTitleName = [self.areaArr[indexPath.item]namec];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    [vc release];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
